﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class LightAnimationManager : MonoBehaviour {

	bool isPlay = false;
	float timeCount = 0;

	Image image;

	public static LightAnimationManager Instance;

	// Use this for initialization
	void Start () 
	{
		Instance = this;
		image = GetComponent<Image>();
		image.enabled = false;
	}
	
	// Update is called once per frame
	void Update () {
		
	}

	public void PlayAnimation()
	{
		if(!isPlay)
		{
			StartCoroutine(PlayAnimEnumerator());
		}
	}

	IEnumerator PlayAnimEnumerator()
	{
		if(isPlay)
		{
			yield break;
		}

		isPlay = true;

		image.enabled = true;

		while(timeCount < 0.5)
		{
			timeCount += Time.deltaTime;
			transform.localPosition = new Vector3(0, -800 + 1400 * timeCount * 2, 0);
			yield return null;
		}

		timeCount = 0;
		image.enabled = false;
		
		isPlay = false;
	}
}
